package com.ksd.oauth2;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ksd.member.Member;

/**
 * @author  zbb
 * @version 创建时间：2015年11月12日 上午10:00:23
 * 类说明
 */
@Service
public class UserService {
	@Autowired
	private UserDao memberDao;
	
	public UserDao getMemberDao() {
		return memberDao;
	}
	public Member findByAccount(String account){
		Member user = null;
		boolean isEmail = isEmail(account);
		if (isEmail) {
			user = memberDao.findByEmail(account);
			return user;
		}
		boolean isMobile = isMobile(account);
		if (isMobile) {
			user = memberDao.findByMobile(account);
		}
		if (user == null) {
			user = memberDao.findByNickname(account);
		}
		return user;
	}
	public static  boolean isMobile(String mobile){
		Pattern p = Pattern.compile("^1[3|4|5|7|8]\\d{9}$");
		Matcher m = p.matcher(mobile);
		return m.matches();
	}
	public static boolean isEmail(String email){
		boolean matchEmail = Pattern.matches("\\w+((\\.|\\-|\\+)\\w+)*@([\\w\\-]+\\.)+(\\w{2,4})+", email);
		return matchEmail;
	}
}
